#define LOG_TAG    "drv_pwm"
#include "drv_pwm.h"

extern TIM_HandleTypeDef htim3;
#define MOTOL_MIDDLE_DUTY 750

//  -90,  -45   0    45    90   
uint32_t pwm_ctrl_table[10] = {
    250,  500, 750, 1000, 1250,  
};

HAL_StatusTypeDef drv_pwm_init(void)
{
    drv_pwm_duty_set(TIM_CHANNEL_1, MOTOL_MIDDLE_DUTY);
    drv_pwm_duty_set(TIM_CHANNEL_2, MOTOL_MIDDLE_DUTY);
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
		
    return HAL_OK;
}

HAL_StatusTypeDef drv_pwm_duty_set(uint32_t ch, uint32_t duty)
{
    HAL_StatusTypeDef ret = HAL_OK;

    uint32_t tick = duty * DRV_PWM_PERIORITY_TICK / 10000;

    __HAL_TIM_SET_COMPARE(&htim3, ch, tick);
    return ret;
}


void drv_pwm_motol_setting(uint32_t val)
{

}
